package org.reborn.engine.input

object MouseButton extends Enumeration{
  type MouseButton = Value
  val LEFT, RIGHT, MIDDLE = Value
}

object MouseMovement extends Enumeration{
  type MouseMovement = Value
  val X, Y, SCROLL_WHEEL = Value
}

/**
 * An input device that makes mouse input available.
 */
trait Mouse extends InputDevice{
  import MouseButton._
  import MouseMovement._
	
  val leftButton:ButtonComponent;
  val rightButton:ButtonComponent;
  val middleButton:ButtonComponent
  
  val changeX:PositionChangeComponent;
  val changeY:PositionChangeComponent;
  val changeScrollWheel:PositionChangeComponent;

  /**
   * @param button the button to query the "clicked" state 
   * @return whether or not the specified button is currently clicked. 
   * If a non-button component is specified, returns false.
   */
  def clicked(button:MouseButton):Boolean = {
	button match{
		case LEFT => Option(leftButton).getOrElse(MissingButton).apply
		case RIGHT => Option(rightButton).getOrElse(MissingButton).apply
		case MIDDLE => Option(middleButton).getOrElse(MissingButton).apply
		case _ => false
	}
  }
  
  /**
   * @param component the component (x, y, or scrollbar change) to query the "moved" state
   * @return the amount of change since the last poll that the component has changed
   * If an invalid component is specified, like a button, returns 0.0f
   */
  def diff(movement:MouseMovement):Float = {
	movement match{
		case X => Option(changeX).getOrElse(MissingPositionChange).apply
		case Y => Option(changeY).getOrElse(MissingPositionChange).apply
		case SCROLL_WHEEL => Option(changeScrollWheel).getOrElse(MissingPositionChange).apply
		case _ => 0.0f
	}
  }
}